<template>
	<view class='price'>
		<text v-if='price>0' style='font-weight:500;color:#FE5A34;' :style="text_size">￥</text>
		<text v-if='price>0' style='font-weight:bold;color:#FE5A34;' :style="price_size">{{price}}</text>
		<text v-if='price>0&&!accurate' style='font-weight:500;margin-left:5upx;color:#888888;' :style="text_size">起</text>

		<text v-if='!(price>0)' style='font-weight:bold;color:#FE5A34;' :style="price_size">免费</text>
	</view>
</template>

<script>
	export default {
		props: {
			tSize: {
				type: String,
				default: '20upx'
			},
			priceSize: {
				type: String,
				default: '30upx'
			},
			price: {
				type: String,
				default: ''
			},
			accurate: {
				type: Boolean,
				default: false
			}
		},
		computed: {
			text_size() {
				return "font-size:" + this.upx2px(this.tSize) + ";line-height:"+this.upx2px(this.tSize)
			},
			price_size(){
				return "font-size:" + this.upx2px(this.priceSize) + ";line-height:"+this.upx2px(this.priceSize)
			}
		},
		methods: {
			upx2px(upx) {
				//如果是upx结尾，则去掉upx并转换为px
				if(upx.endsWith("upx")) {
					upx = upx.replace("upx","")
				} else if(upx.endsWith("px") || upx.endsWith("%")) {//如果是px或%结尾，则原样返回
					return upx
				} 
				//如果没有传入单位，则为upx
				return uni.upx2px(upx) + "px";
			}
		},
		data() {
			return {

			};
		}
	}
</script>

<style>
	.price {
		display: flex;
		flex-direction: row;
		align-items: baseline;
	}
</style>
